<template>
  <el-dialog :visible.sync="visible" title="终止" :close-on-click-modal="false" @opened="handleOpened" @closed="handleClosed">
    <div>
      <el-form ref="form" :model="formData" :rules="formRules" label-width="100px">
        <el-form-item label="意向客户终止跟进原因" prop="terminateDescription">
          <el-input v-model="formData.terminateDescription" type="textarea" show-word-limit maxlength="1024" :autosize="{minRows: 3}" placeholder="意向客户终止跟进原因" clearable />
        </el-form-item>
      </el-form>
      <div class="btn-end">
        <c-button type="default" @click="handleCancel">取消</c-button>
        <c-button type="primary" @click="handleConfirm">确定</c-button>
      </div>
    </div>
  </el-dialog>
</template>
<script>
import { potentialCustomerFollowUpTerminate } from '@/api/channelTask2/potentialCustomerFollowUp'
export default {
  name: 'Termination',
  props: {
  },
  data() {
    return {
      visible: false,
      formData: {
        terminateDescription: ''
      },
      formRules: {
        terminateDescription: [{ required: true, message: '请输入意向客户终止跟进原因', trigger: 'change' }]
      },
      selectData: {}
    }
  },
  methods: {
    openDialog(row) {
      this.selectData = row
      this.visible = true
    },
    handleOpened() {
    },
    handleClosed() {
      this.selectData = {}
      this.$nextTick(() => {
        this.$refs.form && this.$refs.form.resetFields()
        this.$refs.form && this.$refs.form.clearValidate()
      })
    },
    handleCancel() {
      this.visible = false
    },
    handleConfirm() {
      return this.$refs.form.validate().then(() => {
        const data = { ...this.formData }
        data.id = this.selectData.id
        return potentialCustomerFollowUpTerminate(data).then(res => {
          this.$message.success('操作成功!')
          this.$emit('on-success')
          this.visible = false
        })
      })
    }
  }
}
</script>
